package com.situ.admin.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import com.situ.admin.bean.User;

public interface UserMapper {
	@Delete({ "delete from user", "where id = #{id,jdbcType=INTEGER}" })
	int deleteByPrimaryKey(Integer id);

	@Insert({ "insert into user (", "password, head, ", "realname, idcard, ", "phone, money, paypwd, ", "status)",
			"values ( #{username,jdbcType=VARCHAR}, ", "#{password,jdbcType=VARCHAR}, #{head,jdbcType=VARCHAR}, ",
			"#{realname,jdbcType=VARCHAR}, #{idcard,jdbcType=VARCHAR}, ",
			"#{phone,jdbcType=VARCHAR}, #{money,jdbcType=DECIMAL}, #{paypwd,jdbcType=VARCHAR}, ",
			"#{status,jdbcType=INTEGER})" })
	int insert(User record);

	@Select({ "select", "id, username, password, head, realname, idcard, phone, money, paypwd, status", "from user",
			"where id = #{id,jdbcType=INTEGER}" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "username", property = "username", jdbcType = JdbcType.VARCHAR),
			@Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR),
			@Result(column = "head", property = "head", jdbcType = JdbcType.VARCHAR),
			@Result(column = "realname", property = "realname", jdbcType = JdbcType.VARCHAR),
			@Result(column = "idcard", property = "idcard", jdbcType = JdbcType.VARCHAR),
			@Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
			@Result(column = "money", property = "money", jdbcType = JdbcType.DECIMAL),
			@Result(column = "paypwd", property = "paypwd", jdbcType = JdbcType.VARCHAR),
			@Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER) })
	User selectByPrimaryKey(Integer id);

	@Select({ "select", "id, username, password, head, realname, idcard, phone, money, paypwd, status", "from user" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "username", property = "username", jdbcType = JdbcType.VARCHAR),
			@Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR),
			@Result(column = "head", property = "head", jdbcType = JdbcType.VARCHAR),
			@Result(column = "realname", property = "realname", jdbcType = JdbcType.VARCHAR),
			@Result(column = "idcard", property = "idcard", jdbcType = JdbcType.VARCHAR),
			@Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
			@Result(column = "money", property = "money", jdbcType = JdbcType.DECIMAL),
			@Result(column = "paypwd", property = "paypwd", jdbcType = JdbcType.VARCHAR),
			@Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER) })
	List<User> selectAll();

	@Update({ "<script>", "update user", "<set>", "<if test = 'username !=null'> username = #{username} , </if>",
			"<if test = 'password !=null'>  password = #{password} , </if>",
			"<if test = 'head !=null'>  head = #{head} , </if>",
			"<if test = 'realname !=null'>  realname = #{realname} , </if>",
			"<if test = 'idcard !=null'>  idcard = #{idcard} , </if>",
			"<if test = 'phone !=null'>  phone = #{phone} , </if>",
			"<if test = 'money !=null'>  money = #{money} , </if>",
			"<if test = 'paypwd !=null'>  paypwd = #{paypwd} , </if>",
			"<if test = 'status !=null'>  status = #{status} , </if>", "</set>", "where id = #{id}", "</script>" })
	int updateByPrimaryKey(User record);

	@Select({ "<script>", "select * from user", "<where>", "<if test = 'username !=null'> username = #{username}</if>",
			"<if test = 'password !=null'> and password = #{password}</if>",
			"<if test = 'head !=null'> and head = #{head}</if>",
			"<if test = 'realname !=null'> and realname = #{realname}</if>",
			"<if test = 'idcard !=null'> and idcard = #{idcard}</if>",
			"<if test = 'phone !=null'> and phone = #{phone}</if>",
			"<if test = 'money !=null'> and money = #{money}</if>",
			"<if test = 'paypwd !=null'> and paypwd = #{paypwd}</if>",
			"<if test = 'status !=null'> and status = #{status}</if>", "</where>", "</script>" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "username", property = "username", jdbcType = JdbcType.VARCHAR),
			@Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR),
			@Result(column = "head", property = "head", jdbcType = JdbcType.VARCHAR),
			@Result(column = "realname", property = "realname", jdbcType = JdbcType.VARCHAR),
			@Result(column = "idcard", property = "idcard", jdbcType = JdbcType.VARCHAR),
			@Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
			@Result(column = "money", property = "money", jdbcType = JdbcType.DECIMAL),
			@Result(column = "paypwd", property = "paypwd", jdbcType = JdbcType.VARCHAR),
			@Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER) })
	List<User> select(User user);
}